[SYNCOPE-1635] Use singleton bean for each domain for each rule with conf - #264
Conversation
| String domainableBeanNameWithConf = domain + clazz.getName(); | ||
| DefaultListableBeanFactory beanFactory = ApplicationContextProvider.getBeanFactory(); | ||
|
|
||
| if (beanFactory.containsSingleton(domainableBeanNameWithConf)) { |
There was a problem hiding this comment.
The same exact if with statement is also performed in the synchronized block: why?
There was a problem hiding this comment.
This is a double-check lock pattern. Thread takes monitor and executes the logic regarding initialization. Another thread waits until the the monitor is realeased. As soon as first thread releases monitor -> second thread proceeds its work and reaches the additional if clause. As the bean already exists (created by first thread) the second thread is not creating a bean again and not registers it as a singleton one more time.
Do you see any disadvantages it this?
There was a problem hiding this comment.
I see, there is wide literature abut double-check lock pattern, and some is not very pleasant with it, especially for Java implementations.
What would be the disadvantage of simply removing the first if and leaving the whole logic in the synchronized block?
There was a problem hiding this comment.
IMHO: Adding of the additional if clause gives a small improvement in performance (because the acquiring of monitor is not requested).
Am I wrong?
There was a problem hiding this comment.
I am not completely convinced, but let that be :-)
633532c to
fbcbfb0
Compare
…conf